// middleware/loginCheck.js 文件内容
const { verifyToken } = require('../utils/token')

module.exports = async (req, res, next) => {
  const token = req.headers.token || req.body.token;
  if (!token) {
    return res.json({ code: 101, message: '请输入token' })
  }
  const user = await verifyToken(token)
  if (user) {
    // 将当前用户挂载到req上
    req.user = user
    next()
  } else {
    return res.json({ code: 101, message: '输入的token不合法' })
  }
}